#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
struct tlb{
	int c , m , e;
	int s;
	string name;
}f[N];
bool cmp(tlb a , tlb b){
	return a.name < b.name;
}
int main(){
	freopen("opponents.in", "r", stdin);
	freopen("opponents.out", "w", stdout);
	int n;
	cin >> n;
	for(int i = 1 ; i <= n ; i++){
		cin >> f[i].name >> f[i].c >> f[i].e >> f[i].m;
		f[i].s = f[i].c + f[i].e + f[i].m;
	}
	sort(f + 1 , f + n + 1 , cmp);
	for(int i = 1 ; i <= n ; i++){
		for(int j = i + 1 ; j <= n ; j++){
			if(abs(f[i].c - f[j].c ) <= 5 && abs(f[i].e - f[j].e ) <= 5 && abs(f[i].m - f[j].m ) <= 5 && abs(f[i].s - f[j].s ) <= 10){
				cout << f[i].name << " " << f[j].name << endl;
			}
		}
	}
	return 0;
}
